#include<iostream>
#include<opencv2/imgcodecs.hpp>
#include<opencv2/highgui.hpp>
#include<opencv2/imgproc.hpp>
#include<opencv2/objdetect.hpp>
#include<string>
#include<vector>
#include"func.h"

using namespace std;
using namespace cv;

Mat fushibie(Mat mask,Mat img)
{
    vector<vector<Point>>contours;
    findContours(mask,contours,RETR_EXTERNAL,CHAIN_APPROX_SIMPLE);//寻找轮廓

    double maxArea=0;
    double minArea=0;
    int maxContourIdx=-1;//待激活区索引
    int minContourIdx=-1;//R标索引
    for(int i=0;i<contours.size();i++)
    {
        double area=contourArea(contours[i]);
        if(area>maxArea&&area<900)//找到小于900的最大面颊
        {
            maxArea=area;
            maxContourIdx=i;
        }
        if(area<50&&area>1)//找到大于1小于50的面积（R标）
        {
            minArea=area;
            minContourIdx=i;
        }

    }
    Rect boundingRect1;//待激活区
    Rect boundingRect2;//R标
    boundingRect1=cv::boundingRect(contours[maxContourIdx]);
    boundingRect2=cv::boundingRect(contours[minContourIdx]);
    rectangle(img,boundingRect1,Scalar(0,255,0),2);
    rectangle(img,boundingRect2,Scalar(0,255,0),2);
    // cout<<maxArea<<endl;

    jiaodu(boundingRect1,boundingRect2,img);//计算并显示角度

    
    
    return img;
}